package com.my.drinkinggame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.my.screens.AddedCards;
import com.my.screens.CreateCard;
import com.my.screens.MyDrinkingGame;
import com.my.screens.MainMenu;
import com.my.screens.NewGame;
import com.my.screens.RulesScreen;
import com.my.simulation.Simulation;

public class Renderer {
	public SpriteBatch sb;
	public OrthographicCamera cam;
	private static Renderer rend;
	
	
	public static Renderer getInstance(){
		if(rend == null){
			rend = new Renderer();
		}
		return rend;
	}
	
	private Renderer(){
		sb = new SpriteBatch();
		cam = new OrthographicCamera();
		cam.zoom = 1280f/(float)Gdx.graphics.getHeight();
		cam.position.set(Gdx.graphics.getWidth()*cam.zoom/2,Gdx.graphics.getHeight()*cam.zoom/2,0);
		cam.viewportHeight = Gdx.graphics.getHeight();
		cam.viewportWidth = Gdx.graphics.getWidth();
		cam.update();
	}
	
	public void renderGame(MyDrinkingGame game){
		sb.begin();
		game.renderGame(sb);
		sb.end();
	}

	public void renderMainMenu(MainMenu mm) {
		mm.cam.zoom = 1280f/(float)Gdx.graphics.getHeight();
		mm.cam.position.set(Gdx.graphics.getWidth()*mm.cam.zoom/2,Gdx.graphics.getHeight()*mm.cam.zoom/2,0);
		mm.cam.viewportHeight = Gdx.graphics.getHeight();
		mm.cam.viewportWidth = Gdx.graphics.getWidth();
		mm.cam.update();
		sb.setProjectionMatrix(mm.cam.combined);
		sb.begin();
		mm.renderMainMenu(sb);
		sb.end();
	}
	
	public void renderCreateCard(CreateCard cc) {
		cc.cam.zoom = 1280f/(float)Gdx.graphics.getHeight();
		cc.cam.position.set(Gdx.graphics.getWidth()*cc.cam.zoom/2,Gdx.graphics.getHeight()*cc.cam.zoom/2,0);
		cc.cam.viewportHeight = Gdx.graphics.getHeight();
		cc.cam.viewportWidth = Gdx.graphics.getWidth();
		cc.cam.update();
		sb.setProjectionMatrix(cc.cam.combined);
		sb.begin();
		cc.renderCreateCard(sb);
		sb.end();
	}
	
	public void renderAddedCards(AddedCards ac) {
		ac.cam.zoom = 1280f/(float)Gdx.graphics.getHeight();
		ac.cam.position.set(Gdx.graphics.getWidth()*ac.cam.zoom/2,Gdx.graphics.getHeight()*ac.cam.zoom/2,0);
		ac.cam.viewportHeight = Gdx.graphics.getHeight();
		ac.cam.viewportWidth = Gdx.graphics.getWidth();
		ac.cam.update();
		sb.setProjectionMatrix(ac.cam.combined);
		sb.begin();
		ac.renderAddedCards(sb);
		sb.end();
	}
	
	public void renderNewGame(NewGame ng) {
		ng.cam.zoom = 1280f/(float)Gdx.graphics.getHeight();
		ng.cam.position.set(Gdx.graphics.getWidth()*ng.cam.zoom/2,Gdx.graphics.getHeight()*ng.cam.zoom/2,0);
		ng.cam.viewportHeight = Gdx.graphics.getHeight();
		ng.cam.viewportWidth = Gdx.graphics.getWidth();
		ng.cam.update();
		sb.setProjectionMatrix(ng.cam.combined);
		sb.begin();
		ng.renderNewGame(sb);
		sb.end();
	}
	
	public void renderRulesScreen(RulesScreen rs) {
		rs.cam.zoom = 1280f/(float)Gdx.graphics.getHeight();
		rs.cam.position.set(Gdx.graphics.getWidth()*rs.cam.zoom/2,Gdx.graphics.getHeight()*rs.cam.zoom/2,0);
		rs.cam.viewportHeight = Gdx.graphics.getHeight();
		rs.cam.viewportWidth = Gdx.graphics.getWidth();
		rs.cam.update();
		sb.setProjectionMatrix(rs.cam.combined);
		sb.begin();
		rs.renderRulesScreen(sb);
		sb.end();
	}
}
